#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <iomanip>
#include<cstring>
using namespace std;

int main()
{
	int t, i;
	int len = 0;
	int front1, back1 = 0;
	int front2, back2 = 0;
	int front3, back3 = 0;

	char arr1[11] = { 0 };
	char arr2[11] = { 0 };
	char arr3[11] = { 0 };
	cin >> t;
	for (i = 0; i < t; i++)
	{
		cin >> arr1 >> arr2 >> arr3;
		cin >> front1 >> back1;
		cin >> front2 >> back2;
		cin >> front3 >> back3;
		len = back1 - front1 + back2 - front2 + back3 - front3;
		char* ch = new char[len];
		char* ch_copy = ch;
		strncat(ch_copy, arr1 + back1 - front1, back1 - front1);
		strncat(ch_copy+ back1 - front1, arr2 + back2 - front2, back2 - front2);
		strncat(ch_copy+, arr1 + back1 - front1, back1 - front1);
	}
}


